<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的活动</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2 id="doubleClick">我的需求</h2>
        <!--<div class="header-right">
            <div tapmode onclick="" class="nav-right">编辑</div>
        </div>-->
    </header>
</div>

<div class="mescroll" id="mescroll" style="padding-top: 1.5rem">
    <section class="html_section pr30 pl30 ">
        <ul class="userType_list2">
            <li tapmode class="on">我发布的</li>
            <li tapmode>我报名的</li>
        </ul>
        <div class="activity-list">
            <ul id="content">
                <!--<li class="list-li" onclick="commonUrl()" tapmode>
                    <div class="flex-div">
                        <div class="act-img bg-cover" style="background-image: url('../../image/img-activity.png')"></div>
                        <div class="act-info">
                            <h6 class="single-ellipsis">音乐爱好者，一起为音乐疯狂起来</h6>
                            <div class="act-time">
                                <p class="time">周日 09/29 14:00</p>
                                <p class="status status1">报名中</p>
                            </div>
                            <div class="act-place">
                                <p class="place">重庆大学城</p>
                                <p class="num">9/10</p>
                            </div>
                        </div>
                    </div>
                    <div class="detail-bottom">
                        <div class="bottom-tips">
                            <span class="bt-pd toUp">精选</span>
                            <span class="bt-pd tips">#读书会#</span>
                            <div class="bottom-hot">3.3w</div>
                        </div>
                        <div class="act_btn1">取消活动</div>
                    </div>
                </li>
                <li class="list-li" onclick="commonUrl()" tapmode>
                    <div class="flex-div">
                        <div class="act-img bg-cover" style="background-image: url('../../image/img-activity.png')"></div>
                        <div class="act-info">
                            <h6 class="single-ellipsis">音乐爱好者，一起为音乐疯狂起来</h6>
                            <div class="act-time">
                                <p class="time">周日 09/29 14:00</p>
                                <p class="status status2">已取消</p>
                            </div>
                            <div class="act-place">
                                <p class="place">重庆大学城</p>
                                <p class="num">9/10</p>
                            </div>
                        </div>
                    </div>
                    <div class="detail-bottom">
                        <div class="bottom-tips">
                            <span class="bt-pd toUp">精选</span>
                            <span class="bt-pd tips">#读书会#</span>
                            <div class="bottom-hot">3.3w</div>
                        </div>
                    </div>
                </li>-->
            </ul>
            <div class="nodata" style="display: none;"></div>
        </div>
    </section>
</div>

</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/mescroll.min.css"/>
<script type="text/javascript" src="../../script/mescroll.min.js"></script>
<script type="text/javascript">
    var type = 1;
    var page = 1;
    var pullUp = true;
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        pop.loading();
        keybackListener()
        api.addEventListener({
            name: 'evaluate'
        }, function (ret, err) {
            pullUp = true;
            type = 2;
            page = 1;
            $(".nodata").hide();
            getActivity()
        });

        //上拉加载
        /*pullUpLoading(function () {
            if (pullUp == true) {
                getActivity()
            }
        });*/

        /*dropDownRefresh(function () {
            pullUp = true;
            page = 1;
            $(".nodata").hide();
            getActivity()
        });*/
        getActivity()
    }
    //创建MeScroll对象
    var mescroll = new MeScroll("mescroll", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        },
        up: {
            auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false
            isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
            callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }
            /*toTop:{ //配置回到顶部按钮
                src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
                //offset : 1000
            }*/
        }
    });

    /*下拉刷新的回调 */
    function downCallback() {
        pullUp = true;
        page = 1;
        $(".nodata").hide();
        getActivity()

        //mescroll.endErr();
    }

    /*上拉加载的回调 */
    function upCallback() {
        if (pullUp == true) {
            getActivity();
        }else {
            mescroll.endErr();
        }
    }

    function getActivity() {
        var param = {
            token: $api.getStorage('token'),
            type: type,//类型:1我发布的 2我报名的
            page: page,
        }
        getAjax(Interface.get_activity, param, function (res) {
            console.log(jsonChange(res))
            var data = res.data.list;
            if (isDefine(data)) {
                var listHtml = '';
                for (var i = 0; i < data.length; i++) {
                    var listData = data[i];

                    var actHtml = '';//活动内容
                    var actStatus = '';//活动状态
                    //是否置顶
                    var toUp = '';
                    var hotHtml = '';
                    //顶置，标签，热度
                    /*if (listData.recommend == 1) {
                        toUp = '<span class="bt-pd toUp">活动</span>';
                    }*/
                    toUp = '<span class="bt-pd toUp">需求</span>';
                    var tips = '';//标签
                    if (isDefine(listData.cut_list)) {
                        for (var z = 0; z < listData.cut_list.length; z++) {
                            tips += '<span class="bt-pd tips">#' + listData.cut_list[z] + '#</span>'
                        }
                    }
                    var being = '';//活动是否开始
                    var eva_param1 = {'activity_id': listData.id, 'status': 1};//去评星
                    var eva_param2 = {'activity_id': listData.id, 'status': 2};//查看评星
                    if (type == 1) {
                        if (listData.status == 1) {
                            being = '<div class="act_btn1" tapmode onclick="userCancelAct(' + listData.id + ')">取消发布</div>'
                        }
                    } else {
                        if (listData.status == 1) {
                            being = '<div class="act_btn1" tapmode onclick="userCancelSign(' + listData.id + ')">取消发布</div>'
                        } else if (listData.status == 3 && listData.evaluate_status == 2) {
                            being = '<div class="act_btn1" tapmode onclick=\'commonUrl("activity_eva",' + jsonChange(eva_param1) + ')\'>去评星</div>'
                        } else if (listData.status == 3 && listData.evaluate_status == 1) {
                            being = '<div class="act_btn1" tapmode onclick=\'commonUrl("activity_eva",' + jsonChange(eva_param2) + ')\'>查看评星</div>'

                        }
                    }

                    hotHtml = '<div class="detail-bottom">' +
                        '              <div class="bottom-tips">' + toUp + tips + '<div class="bottom-hot">' + listData.hot_number + '</div>' +
                        '</div>' + being +
                        '          </div>';

                    if (listData.status == 1) {
                        actStatus = '<p class="status status1">报名中</p>'
                    } else if (listData.status == 2) {
                        actStatus = '<p class="status status3">进行中</p>'
                    } else if (listData.status == 3) {
                        actStatus = '<p class="status status2">已结束</p>'
                    } else if (listData.status == 4) {
                        actStatus = '<p class="status status3">报名截止</p>'
                    } else {
                        actStatus = '<p class="status status2">已取消</p>'
                    }
                    var icon_img = ''
                    if(isDefine(listData.icons_path)){
                        icon_img = listData.icons_path[0]
                    }else {
                        icon_img = listData.background_path;
                    }

                    var activity = {'activity_id': listData.id};
                    actHtml = '<div class="flex-div" tapmode onclick=\'commonUrl("../activity/activity_index",' + jsonChange(activity) + ')\'>' +
                        '                    <div class="act-img bg-cover" style="background-image: url(' + ajaxUrl + icon_img + ')"></div>' +
                        '                    <div class="act-info">' +
                        '                        <h6 class="single-ellipsis">' + listData.title + '</h6>' +
                        '                        <div class="act-time">' +
                        '                            <p class="time">' + listData.week + ' ' + listData.start_date + '</p>' + actStatus + '</div>' +
                        '                        <div class="act-place">' +
                        '                            <p class="place">' + listData.address + '</p>' +
                        '                            <p class="num">' + listData.sum_number + '/' + listData.number + '</p>' +
                        '                        </div>' +
                        '                    </div>' +
                        '                </div>';

                    listHtml += '<li style="border-bottom: 1px #f0f0f0 solid;" class="list-li">' + actHtml + hotHtml + '</li>'

                }

                if (page == 1) {
                    $("#content").html(listHtml)
                } else {
                    $("#content").append(listHtml)
                }
                page++
                pullUp = true;
            } else {
                if (page == 1) {
                    $("#content").html(noData)
                } else {
                    $(".nodata").show();
                }
                pullUp = false;

            }

            pop.close()
            mescroll.endErr()
        }, function (error) {
            $("#content").html(noData);
            pullUp = false;
            pop.notice(error.msg);
            pop.close()
            mescroll.endErr()
        })
    }


    //取消活动
    function userCancelAct(activity_id) {
        pop.loading();
        cancelAct(activity_id, function (res) {
            pop.notice(res.msg)
            pop.close();
            setTimeout(function () {
                page = 1;
                pullUp = true;
                $(".nodata").hide();
                getActivity()
            }, 1000)
        })
    }

    //取消活动报名
    function userCancelSign() {
        pop.loading();
        cancelSign(activity_id, function (res) {
            pop.notice(res.msg)
            pop.close();
            setTimeout(function () {
                page = 1;
                pullUp = true;
                $(".nodata").hide();
                getActivity()
            }, 1000)
        })
    }


    $(".userType_list2 li").click(function () {

        $(".userType_list2 li").removeClass("on");
        $(this).addClass("on");
        if ($(this).index() == 0) {
            type = 1;

        } else {
            type = 2;
        }
        page = 1;
        pullUp = true;
        $(".nodata").hide();
        getActivity()
    })
    //取消
</script>
